//#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//using namespace std;
typedef struct node
{
    char data;
    struct node *lchild;
    struct node *rchild;
} *btree,bnode;
btree recover(char pre[],char mid[],int len)
{
    btree bt;

    int i;
    if(len)
    {
        bt=(btree)malloc(sizeof(bnode));
        bt->data=pre[0];
        for(i=0; i<len; i++)
        {
            if(mid[i]==pre[0])
                break;
        }
        bt->lchild=recover(pre+1,mid,i);
        bt->rchild=recover(pre+i+1,mid+i+1,len-i-1);
        return bt;
    }
    else
        return NULL;
    // recover(bt->lchild,pre.substr(1,len),mid,i);
    // recover(bt->rchild,pre.substr(1+i,len),mid.substr(i+1,len),len-i-1);
}
int getlength(btree bt)
{
    int l,r;
    if(bt==NULL)
        return 0;
    else
    {
        l=getlength(bt->lchild);
        r=getlength(bt->rchild);
        return l>r?l+1:r+1;
    }
}
int main()
{
    int len;
    btree bt;
   // bt=(btree)malloc(sizeof(bnode));

    scanf("%d",&len);
    char pre[len],mid[len];
    getchar();
    gets(pre);
    gets(mid);

    bt=recover(pre,mid,len);

    printf("%d",getlength(bt));


}
